package com.hien.controler;

import java.io.InputStream;
import java.util.ArrayList;

import com.hien.model.TricksPranks;
import com.hien.starting.R;

import android.content.Context;

public class FileHandle {

public String readingFromFile(Context context) {
	String result  = "";
	try{
		InputStream is  =  context.getResources().openRawResource(R.raw.classical_pranks);

		byte[] b = new byte[is.available()];
		is.read(b);
		result += new String(b);
		is.close();
		}
	catch (Exception e) {
		e.printStackTrace();
	}
return result;	
}


public ArrayList<TricksPranks> getItems(String content){
	ArrayList<TricksPranks> result = new ArrayList<TricksPranks>();
	String splitString[] = content.split(";");
	if(splitString.length>0){
		for(String str : splitString){
			TricksPranks tp = new TricksPranks();
			int s = str.indexOf("-");
			String tit = str.substring(2, str.indexOf("-") - 1);
			String body  = str.substring(s + 1);
			System.out.println("title" + tit);
			System.out.println("body" + body);
			tp.setTitle(tit);
			tp.setBody(body);
			result.add(tp);
		}
	}
	if(result.size() == 0) return null;
	return result;
}

}
